package org.liu.knowledge.func;

import dev.langchain4j.agent.tool.ToolSpecification;
import dev.langchain4j.data.message.UserMessage;
import dev.langchain4j.model.chat.ChatLanguageModel;
import dev.langchain4j.model.chat.request.ChatRequest;
import dev.langchain4j.model.chat.request.ChatRequestParameters;
import dev.langchain4j.model.chat.request.json.JsonObjectSchema;
import dev.langchain4j.model.chat.response.ChatResponse;
import dev.langchain4j.model.ollama.OllamaChatModel;
import dev.langchain4j.model.ollama.OllamaStreamingChatModel;

import java.util.List;

public class FuncApi {
    static String MODEL_NAME = "qwen2.5:14b";
    static String BASE_URL = "http://localhost:11434"; // local ollama base url


    public static void main(String[] args) {
        ChatLanguageModel model = OllamaChatModel.builder()
                .baseUrl(BASE_URL)
                .modelName(MODEL_NAME)
                .logRequests(true)
                .logResponses(true)
                .build();

//        System.out.println(model.chat("你好啊"));

        ToolSpecification tool = ToolSpecification.builder()
                .name("calculator")
                .description("输入两个数求和")
                .parameters(JsonObjectSchema.builder()
                        .addIntegerProperty("a", "第一个参数")
                        .addIntegerProperty("b", "第二个参数")
                        .required("a", "b")
                        .build())
                .build();

        ChatResponse chatResponse = model.chat(ChatRequest.builder()
                .messages(UserMessage.from("我的两个数字5和8"))
                .parameters(ChatRequestParameters.builder().toolSpecifications(tool).build())
//                .toolSpecifications(tool)
                .build());

        chatResponse.aiMessage().toolExecutionRequests().forEach(toolExecutionRequest -> {
//            System.out.println(toolExecutionRequest.name());
//            System.out.println(toolExecutionRequest.arguments());
        });

        System.out.println(chatResponse);
    }
}
